// 引入 Mock
import Mock from "mockjs";

// 定义数据类型
const { data } = Mock.mock({
  // 数据条数
  "data|100": [
    {
      // 商品种类

      // 商品编号
      date: /\d{10}/,
      //商品名称 10个中文组成的名字
      name: "@ctitle(4)",
      //商品地址  随机城市
      address: "@city",

      "price|30-500": 30,
      Tick: false,
      "stock|100-600": 100,
      "sales|2000-6000": 2000,
      "state|1": ["已下架", "销售中"],
      data: "2022",
      "id|+1": 1,
    },
  ],
});

interface ParamsType {
  pageSize: number;
  currentPage: number;
}

class GoodsServer {
  getData(params: ParamsType) {
    const { pageSize, currentPage } = params;
    const result = data.slice(
      (currentPage - 1) * pageSize,
      pageSize * currentPage
    );
    return new Promise((resolve) => {
      resolve({
        status: 0,
        result: result,
        count: data.length,
      });
    });
  }
}

const goods = new GoodsServer();

export default goods;
